<template>
  <div class="content">
    <div class="tital">新增到款</div>

    <el-form ref="form" :model="form" label-width="80px" class="form">
      <el-form-item label="状态" class="hzaungtai">
        <el-radio-group v-model="form.status">
          <el-radio :label="1">合同有效</el-radio>
          <el-radio :label="2">合同失效</el-radio>
          <el-radio :label="3">待审核</el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item label="备注" class="beizhu">
        <el-input type="textarea" v-model="form.desc" class="desc"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="success" @click="onSubmit">保存</el-button>
        <el-button type="info" @click="back">关闭</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { timeFormat } from "../../../utils/utils";
import { contranctstatus } from "../../../http/apis/agreementApi";
export default {
  data() {
    return {
      form: {
        status: '',
        desc: "",
        time: "",
      },
    };
  },

  mounted(){
    if(this.$route.query.info.contract_status_no == "合同有效"){
      this.form.status = 1
    }else if(this.$route.query.info.contract_status_no == "合同无效"){
      this.form.status = 2
    }else if(this.$route.query.info.contract_status_no == "转审核"){
      this.form.status = 3
    }
  },

  methods: {
    onSubmit() {
      this.form.time = timeFormat(Date.now());
      console.log("state",this.form.status);
      console.log(this.form.desc);
      console.log(this.form.time);
      console.log(this.$route.query.info.contract_id);
      if (this.$route.query.info.employee_id === "超级管理员") {
        this.$route.query.info.employee_id = 0;
      } else {
        this.$route.query.info.employee_id = 1;
      }
      // console.log(this.$route.query.info.employee_id);
      contranctstatus(
        this.form.status,
        this.form.desc,
        this.form.time,
        this.$route.query.info.contract_id,
        this.$route.query.info.employee_id,
      )
        .then((res) => {
          console.log("请求成功", res);
          // console.log(typeof this.$route.query.id);
          if (this.$route.query.id == "1") {
            // console.log(1);
            this.$router.push({
              path: "/agreement/agreementNext",
              query: res.data,
            });
          }else if(this.$route.query.id == "2"){
              this.$router.push({
              path: "/agreement/todayIncrease",
              query: res.data,
            });
          }else if(this.$route.query.id == "3"){
              this.$router.push({
              path: "/agreement/weekIncrease",
              query: res.data,
            });
          }else if(this.$route.query.id == "4"){
              this.$router.push({
              path: "/agreement/monthIncrease",
              query: res.data,
            });
          }else if(this.$route.query.id == "5"){
              this.$router.push({
              path: "/agreement/todayDeal",
              query: res.data,
            });
          }else if(this.$route.query.id == "6"){
              this.$router.push({
              path: "/agreement/weekDeal",
              query: res.data,
            });
          }else if(this.$route.query.id == "7"){
              this.$router.push({
              path: "/agreement/monthDeal",
              query: res.data,
            });
          }else if (this.$route.query.id == "8") {
              this.$router.push({
              path: "/agreement/monthDeal",
              query: res.data,
            });
          }
        })
        .catch((err) => {
          console.log("请求失败", err);
        });
    },
    back() {
      this.$route.back()
    },
  },
};
</script>

<style lang="scss" scoped>
.tital {
  height: 20px;
  padding-left: 15px;
  padding-top: 15px;
  box-sizing: border-box;
  font-size: 24px;
  font-weight: 1000px;
}
.form {
  margin-top: 40px;
}
.desc {
  width: 500px;
}
.beizhu {
  margin-top: 25px;
}
.hzaungtai {
  margin-left: 20px;
}
.el-form-item__content {
  padding: 20px;
  box-sizing: border-box;
}
</style>